<?php
/**
 * @package		Gantry Template Framework - RocketTheme
 * @version		1.3 December 12, 2011
 * @author		RocketTheme http://www.rockettheme.com
 * @copyright 	Copyright (C) 2007 - 2011 RocketTheme, LLC
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 *
 * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
 *
 */
defined('JPATH_BASE') or die();

gantry_import('core.gantryfeature');

class GantryFeatureStyleDeclaration extends GantryFeature {
    var $_feature_name = 'styledeclaration';

    function isEnabled() {
        global $gantry;
        $menu_enabled = $this->get('enabled');

        if (1 == (int)$menu_enabled) return true;
        return false;
    }
    
function init() {
        global $gantry;
		$browser = $gantry->browser;
		
		// Main Background	
        $css = '#rt-page-surround, .title3 .module-title, .box3 .rt-block, .contentbox3 {background-color:'.$gantry->get('main-background').';}'."\n";
        $css .= '.box3 .rt-block, .contentbox3 {border-color:'.$gantry->get('main-background').';}'."\n";
        $css .= '#rt-feature, #rt-bottom, #rt-feature a:hover, #rt-bottom a:hover, .box3 .rt-block, .contentbox3, .box3 .rt-block a:hover, .contentbox3 a:hover, .title3 .title, #rt-subnavigation .menu li .item, .readonstyle-link #rt-feature .readon:hover span, .readonstyle-link #rt-feature .readon:hover .button, .readonstyle-link #rt-bottom .readon:hover span, .readonstyle-link #rt-bottom .readon:hover .button {color:'.$gantry->get('main-text').';}'."\n";
        $css .= '#rt-feature a, #rt-bottom a, #rt-subnavigation .menu li:hover .item, #rt-subnavigation .menu li.active .item, .readonstyle-link #rt-feature .readon span, .readonstyle-link #rt-feature .readon .button, .readonstyle-link #rt-bottom .readon span, .readonstyle-link #rt-bottom .readon .button, .box3 .rt-block a, .contentbox3 a {color:'.$gantry->get('main-link').';}'."\n";
        $css .= '#rt-feature .readon, #rt-bottom .readon, #rt-feature .roktabs-wrapper .roktabs-links ul, #rt-feature .roktabs-wrapper .active-arrows, #rt-bottom .roktabs-wrapper .roktabs-links ul, #rt-bottom .roktabs-wrapper .active-arrows {background-color:'.$gantry->get('main-accent').';}'."\n";
        
        // Top Block
        $css .= '#rt-top-surround, .rt-navigation-top, .rt-navigation-bar {background-color:'.$gantry->get('topblock-background').';}'."\n";
        $css .= '#rt-top-surround, #rt-top, .menutop li > .item, .readonstyle-link #rt-top-surround .readon:hover span, .readonstyle-link #rt-top-surround .readon:hover .button, #rt-top-surround a:hover, #rt-top a:hover {color:'.$gantry->get('topblock-text').';}'."\n";
        $css .= '#rt-top-surround a, #rt-top a, .menutop li.root.active > .item, .rt-splitmenu .menutop li.active > .item, .readonstyle-link #rt-top-surround .readon span, .readonstyle-link #rt-top-surround .readon .button {color:'.$gantry->get('topblock-link').';}'."\n";
        $css .= '#rt-top-surround .readon, .fusion-submenu-wrapper, .menutop li.root:hover > .item, .menutop li.root.f-mainparent-itemfocus > .item, .rt-splitmenu .menutop li:hover .item, #rt-top-surround .roktabs-wrapper .roktabs-links ul, #rt-top-surround .roktabs-wrapper .active-arrows {background-color:'.$gantry->get('topblock-accent').';}'."\n";
        
        // Main Body
        $css .= '#rt-logo, #rt-container-bg .readon, .title1 .module-title, .rt-article-icons .icon, .rt-article-icons ul li a, .roktabs-wrapper .roktabs-links ul, .roktabs-wrapper .active-arrows, body .roknewspager-pages .roknewspager-numbers li {background-color:'.$gantry->get('body-accent').';}'."\n";
        $css .= '#rt-container-bg, #rt-showcase, #rt-header, .box2 .rt-block, .box4 .rt-block, #rt-showcase .roktabs-links ul li, .readonstyle-link #rt-container-bg .readon:hover span, .readonstyle-link #rt-container-bg .readon:hover .button {color:'.$gantry->get('body-text').';}'."\n";
        $css .= '.rt-article-icons a:hover .print, .rt-article-icons a:hover .email, .rt-article-icons a:hover .pdf, .rt-article-icons .edit:hover, .rt-article-icons ul li a:hover {background-color:'.$gantry->get('body-text').';}'."\n";
        $css .= '#rt-container-bg a, #rt-showcase a, #rt-header a, .box2 .rt-block a, .box4 .rt-block a, .roktabs-links ul li.active span, .readonstyle-link #rt-container-bg .readon span, .readonstyle-link #rt-container-bg .readon .button {color:'.$gantry->get('body-link').';}'."\n";
        $css .= '#rt-container-bg .title span {color:'.$gantry->get('body-accent').';}'."\n";
        $css .= 'body ul.checkmark li:after, body ul.circle-checkmark li:before, body ul.square-checkmark li:before, body ul.circle-small li:after, body ul.circle li:after, body ul.circle-large li:after {border-color:'.$gantry->get('body-accent').';}'."\n";
        $css .= 'body ul.triangle-small li:after, body ul.triangle li:after, body ul.triangle-large li:after {border-left-color:'.$gantry->get('body-accent').';}'."\n";
        
        // Footer Block
        $css .= 'body, #rt-footer-surround {background-color:'.$gantry->get('footerblock-background').';}'."\n";
        $css .= '#rt-footer-surround, #rt-footer, #rt-copyright, .readonstyle-link #rt-footer-surround .readon:hover span, .readonstyle-link #rt-footer-surround .readon:hover .button, #rt-footer-surround a:hover, #rt-footer a:hover, #rt-copyright a:hover {color:'.$gantry->get('footerblock-text').';}'."\n";
        $css .= '#rt-footer-surround a, #rt-footer a, #rt-copyright a, .readonstyle-link #rt-footer-surround .readon span, .readonstyle-link #rt-footer-surround .readon .button {color:'.$gantry->get('footerblock-link').';}'."\n";
        $css .= '#rt-footer-surround .readon, #rt-footer-surround .roktabs-wrapper .roktabs-links ul, #rt-footer-surround .roktabs-wrapper .active-arrows {background-color:'.$gantry->get('footerblock-accent').';}'."\n";
        
        if ($gantry->get('static-enabled')) {
            // do file stuff
            jimport('joomla.filesystem.file');
            $filename = $gantry->templatePath.DS.'css'.DS.'static-styles.css';

            if (file_exists($filename)) {
                if ($gantry->get('static-check')) {
                    //check to see if it's outdated

                    $md5_static = md5_file($filename);
                    $md5_inline = md5($css);

                    if ($md5_static != $md5_inline) {
                        JFile::write($filename, $css);
                    }
                }
            } else {
                // file missing, save it
                JFile::write($filename, $css);
            }
            // add reference to static file
            $gantry->addStyle('static-styles.css',99);

        } else {
            // add inline style
            $gantry->addInlineStyle($css);
        }
        

		$this->_disableRokBoxForiPhone();

		// Style Inclusion
		$cssstyle = $gantry->get('cssstyle');
		$gantry->addStyle($cssstyle.".css");
		$gantry->addStyle('overlays.css');
		$bodystyle = $gantry->get('body-background');
		$gantry->addStyle('bodystyle-'.$bodystyle.'.css');
		if ($gantry->get('typography-enabled')) $gantry->addStyle('typography.css');
		if ($gantry->get('extensions')) $gantry->addStyle('extensions.css');
        if ($gantry->get('extensions')) $gantry->addStyle('extensions-overlays.css');
		if ($gantry->get('extensions')) $gantry->addStyle('extensions-body-'.$bodystyle.'.css');
		if ($gantry->get('thirdparty')) $gantry->addStyle('thirdparty.css');

	}

	function _disableRokBoxForiPhone() {
		global $gantry;

		if ($gantry->browser->platform == 'iphone') {
			$gantry->addInlineScript("window.addEvent('domready', function() {\$\$('a[rel^=rokbox]').removeEvents('click');});");
		}
	}

}